# Bot for avatar rating thread
# By Cee Pee

import imghdr
import forumapi

def settings(settings):
	settings.add_arg("thread", type="int", help="thread ID to post in")

def main(me, settings, options):
	scores = {
		"rgb": 0,
		"gif": 2,
		"pbm": 0,
		"pgm": 0,
		"ppm": 0,
		"tiff": 0,
		"rast": 0,
		"xbm": 0,
		"jpeg": 3,
		"bmp": 1,
		"png": 5,
	}
	
	post = me.prepare_post(t=args.thread)
	thread = post.thread
	print(repr(thread.latest_post))
	
	user = thread.latest_post.user
	print(repr(user))
	
	if not user.avatar:
		print("No avatar detected.")
	else:
		avatar = user.avatar.content
		
		type = imghdr.what(None, bytes(data.data, site.encoding))
		result = scores[type]
		
		text = "{0}/5 (matched type: {1})".format(result, type)
		print(text)
		
		post.message = text
		result = post.post()
		
		print(repr(result))

if __name__ == "__main__":
	forumapi.run(main, options=settings, supported_types=["vbulletin"])
